<?php

namespace App\Ma\States;

use App\Ma\Entities\Matrix;
use App\Model\RoundActionModel;
use App\Model\RoundsModel;
use App\Model\UsersModel;

/**
 * 状态
 * Class MoState
 * @package App\Ma\States
 */
class BaseState
{

    /**
     * 回合
     * @var RoundsModel
     */
    public $round;

    /**
     * 当前回合动作
     * @var RoundActionModel
     */
    public $action;


    /**
     * @var int
     */
    public $actionVal;

    /**
     * 当前玩家
     * @var UsersModel
     */
    protected $user;

    /**
     * 手牌矩阵
     * @var Matrix
     */
    protected $matrix;


    public function __construct(RoundActionModel $action, RoundsModel $round)
    {
        $this->round = $round;
        $this->action = $action;
        $this->actionVal = $action->getActionVal();
        $this->initMatrix();
    }

    /**
     * 当前动作发起的用户
     * @return UsersModel
     */
    public function getUser(): UsersModel
    {
        if (!$this->user) {
            $this->user = $this->action->User()->first();
        }
        return $this->user;
    }

    /**
     * 当前手牌的矩阵
     * @return Matrix
     */
    public function initMatrix(): Matrix
    {
        if (!$this->matrix) {
            $this->matrix = new Matrix($this->action->getCurrentCards());
        }
        return $this->matrix;

    }


}